/*
 * @Author: new-wang
 * @Date: 2025-08-29 16:35:35
 * @LastEditors: new-wang
 * @LastEditTime: 2025-09-02 16:39:43
 * @FilePath: \nest-demo\src\entityAll\entities\UserProfiles.ts
 * @Description: 用户信息分表： 存放用户的详细个人资料，这些信息不拥护登录认证，访问频率也可能较低
 */
import {
  Column,
  Entity,
  Index,
  JoinColumn,
  OneToOne,
  PrimaryGeneratedColumn,
} from "typeorm";
import { Users } from "./Users";

@Index("fk_user_id", ["userId"], {})
@Index("user_id", ["userId"], { unique: true })
@Entity("user_profiles", { schema: "nest-demo" })
export class UserProfiles {
  @PrimaryGeneratedColumn({ type: "int", name: "id", unsigned: true })
  id: number;

  @Column("bigint", {
    name: "user_id",
    unique: true,
    comment: "一对一关系",
    unsigned: true,
  })
  userId: string;

  @Column("varchar", {
    name: "avatar",
    nullable: true,
    comment: "存储用户头像的文件路径或 URL，而不是直接存储图片数据",
    length: 255,
  })
  avatar: string | null;

  @Column("varchar", {
    name: "first_name",
    nullable: true,
    comment:
      "first_name & last_name: 拆分开比一个 full_name 字段更灵活，便于国际化",
    length: 50,
  })
  firstName: string | null;

  @Column("varchar", { name: "last_name", nullable: true, length: 50 })
  lastName: string | null;

  @Column("date", { name: "date_of_birth", comment: " 出生日期" })
  dateOfBirth: string;

  @Column("enum", {
    name: "gender",
    nullable: true,
    comment: "性别",
    enum: ["male", "female", "other", "undisclosed"],
    default: 'undisclosed',
  })
  gender: "male" | "female" | "other" | "undisclosed" | null;

  @Column("text", { name: "bio", nullable: true, comment: "个人简介" })
  bio: string | null;

  @Column("varchar", {
    name: "website",
    nullable: true,
    comment: "网站",
    length: 200,
  })
  website: string | null;

  @OneToOne(() => Users, (users) => users.userProfiles, {
    onDelete: "CASCADE",
    onUpdate: "NO ACTION",
  })
  @JoinColumn([{ name: "user_id", referencedColumnName: "id" }])
  user: Users;
}
